/**
 * Generate code from /{{projectName}}-core/src/main/java/{{packageName}}/{{apis}}/mapping/{{apiDtos@DEFAULT}}Mapping.java.hbs
 */
package cn.ibizlab.core.authentication.mapping;

import cn.ibizlab.core.ad.domain.SysPerson;
import cn.ibizlab.core.authentication.domain.AuthInfo;
import cn.ibizlab.core.authentication.domain.AuthLogin;
import cn.ibizlab.core.authentication.domain.AuthUserImpl;
import cn.ibizlab.util.security.AuthUser20Impl;
import cn.ibizlab.util.security.AuthenticationInfo;
import org.mapstruct.*;

import java.util.List;

@Mapper(componentModel = "spring", uses = {},
        nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE,
        nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS)
public interface AuthInfoMapping {

    @Mappings({
            @Mapping(target ="enabled", ignore = true),
    })
    SysPerson toSysPerson(AuthUserImpl authUser);

    @Mappings({
            @Mapping(target ="enabled", ignore = true),
    })
    AuthUserImpl toAuthUser(SysPerson sysPerson);

    AuthUserImpl toAuthUser(AuthInfo authInfo);

    @Mappings({
            @Mapping(target ="memberOf", source = "memberOf",dependsOn = {"organizationId","dc"}),
            @Mapping(target ="roles", source = "roles",dependsOn = "memberOf"),
            @Mapping(target ="authorities", source = "authorities",dependsOn = "roles"),
            @Mapping(target ="superUser", source = "superUser",dependsOn = "authorities"),
            @Mapping(target ="apiUser", source = "apiUser",dependsOn = "authorities"),
    })
    AuthUser20Impl toAuthUser20Impl(AuthUserImpl authUser);

    AuthenticationInfo toAuthenticationInfo(AuthLogin authLogin);

    AuthenticationInfo.AuthInfo toAuthenticationInfo(AuthInfo info);


    @Mappings({
            @Mapping(target ="grants", source = "roles",dependsOn = "memberOf"),
    })
    AuthInfo toAuthInfo(AuthUser20Impl authUser);

    AuthInfo toAuthInfo(AuthUserImpl authUser);

    List<SysPerson> toSysPerson(List<AuthUserImpl> authUser);

    @Mappings({
            @Mapping(target ="enabled", ignore = true),
            @Mapping(source = "password", target ="userPassword"),
            @Mapping(source = "username", target ="uid"),
    })
    SysPerson toSysPerson(AuthUser20Impl user);

    @Mappings({
            @Mapping(source = "userPassword", target ="password"),
            @Mapping(source = "uid", target ="username"),
    })
    AuthUser20Impl toAuthUser20Impl(SysPerson person);
}
